/*


Simpson's 1/3 rule

Author: Viahwajeet Dusane

*/



#include<stdio.h>
#include<string.h>


double fun(double);
int main()
{
	double arr[10];
	double h,temp,sum1=0.0,sum2=0.0,sum3=0.0;
	double n=10.0;
	
	int i=0;
	h=1.0/n;
	double lim=0,pi;
	
	printf("value of h is ====>%f\n",h);
	while(lim<=1.0)
	{
		
		temp=fun(lim);
		arr[i]=temp;
		lim=lim+h;
		i++;
		printf("value of lim is ==========>%f\n",lim);
		printf("value of i is ============>%f\n",i);
		printf("value of arr[%d] is ======>%f\n",i,arr[i]);

	}
	 
	for(i=0;i<10;i++)
	{
		if((i==0)||(1==9))
		{
			sum1=sum1+arr[i];
		}
		else
		{
			if((i%2)==0)
			{
				sum2=sum2+arr[i];
			}
			else
				sum3=sum3+arr[i];
		}
	}	
	
	pi=4*(h/3*(sum1+4*sum2+2*sum3));
	printf("value of pi is ========>%f",pi);
	
}


double fun(double a)
{
	double res;
	res = 1/(1+a*a);
	return(res);
}
